import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vite.dev/config/
export default defineConfig({
  plugins: [react()],
  server: {
    host: true, // 监听所有网络接口，允许外部访问
    port: 5173,
    hmr: {
      host: 'localhost' // HMR 热更新使用 localhost
    },
    proxy: {
      // 配置API转发到远程服务器
      '/api/v1': {
        target: 'https://api.csqaq.com',
        changeOrigin: true
      },
      // 配置本地配置服务器转发
      '/api/config': {
        target: 'http://localhost:3001',
        changeOrigin: true
      },
      // 备用代理路径
      '/api-proxy': {
        target: 'https://api.csqaq.com',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api-proxy/, '')
      }
    }
  }
})
